//
//  ZXZBaseVisitView.swift
//  up_learnWB
//
//  Created by Mac on 16/10/21.
//  Copyright © 2016年 www.ZXZ123.com. All rights reserved.
//

import UIKit

class ZXZBaseVisitView: UIView {

    // 创建showImgName  houseName message
    // 展示图片
    private lazy var showImg = UIImageView(image: UIImage.init(named: "visitordiscover_feed_image_smallicon"))

    // 小房子视图
    private lazy var houseImg:UIImageView =  UIImageView(image: UIImage.init(named: "visitordiscover_feed_image_house"))

    // 遮罩
    private lazy var coverImg:UIImageView =  UIImageView(image: UIImage.init(named: "visitordiscover_feed_mask_smallicon"))


    // 展示信息
    private lazy var messageLabel:UILabel = UILabel.cz_label(withText: "关注一些人，回这里看看有什么惊喜关注一些人，回这里看看有什么惊喜",
                                                             fontSize: 14,
                                                             color: UIColor.gray)

    // 取消按钮
     lazy var registerBtn:UIButton = UIButton.cz_textButton("注册",
                                                                 fontSize: 16,
                                                                 normalColor: UIColor.gray,
                                                                 highlightedColor: UIColor.orange,
                                                                 backgroundImageName: "common_button_white_disable")

     lazy var loginBtn:UIButton = UIButton.cz_textButton("确定",
                                                                  fontSize: 16,
                                                                  normalColor: UIColor.orange,
                                                                  highlightedColor: UIColor.gray,
                                                                  backgroundImageName: "common_button_white_disable")

    /// s设置数据 展示访客视图
    var visitDic:[String:String]?{
        didSet{

            // 显示的信息  imgName   messageName
            guard let imgName:String = visitDic?["imgName"],
                let messageName:String = visitDic?["messageName"]
                else {
                    return
            }

            // 3> 设置图像，首页不需要设置
            if imgName == "" {
                startAnimation()
                return
            }

            showImg.image = UIImage(named: imgName)
            messageLabel.text = messageName


            houseImg.isHidden = true
            coverImg.isHidden = true
        }



    }

    // 开始首页小圆环的转动
    private func startAnimation(){

        let startAn = CABasicAnimation(keyPath: "transform.rotation")
        startAn.toValue = 2*M_PI
        startAn.repeatCount = MAXFLOAT
        startAn.duration = 20
        // 一直转转转
        startAn.isRemovedOnCompletion = false
        showImg.layer.add(startAn, forKey: nil)
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = UIColor.init(colorLiteralRed: 0.93, green: 0.93, blue: 0.93, alpha: 1)
        setupUI()

    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    private  func setupUI(){
        // 展示的图像为 90
        addSubview(showImg)
        showImg.frame = CGRect(x: (UIScreen.cz_screenWidth()-90*UIScreen.cz_scale())/2, y: UIScreen.cz_screenHeight()/2-90*UIScreen.cz_scale(), width: 90*UIScreen.cz_scale(), height: 90*UIScreen.cz_scale())

        // 遮罩
        addSubview(coverImg)
        coverImg.frame = CGRect(x: showImg.left, y: showImg.top, width: showImg.width, height: showImg.height)

        // 小房子
        addSubview(houseImg)
        houseImg.frame = CGRect(x: showImg.left+45*UIScreen.cz_scale()/2, y: showImg.top+45*UIScreen.cz_scale()/2, width: 45*UIScreen.cz_scale(), height: 45*UIScreen.cz_scale())


        // 展示消息按钮  宽度为屏幕宽度的一般
        addSubview(messageLabel)
        messageLabel.textAlignment = NSTextAlignment.center
        messageLabel.frame = CGRect(x: UIScreen.cz_screenWidth()/6.0, y: showImg.bottom+10, width: UIScreen.cz_screenWidth()/3.0*2.0, height: 40)
        messageLabel.sizeToFit()

        // 添加取消按钮
        addSubview(registerBtn)
        registerBtn.frame  =  CGRect(x: messageLabel.left, y: messageLabel.bottom+20, width: messageLabel.width/3, height: 35)

        
        addSubview(loginBtn)
        loginBtn.frame  =  CGRect(x: messageLabel.right-messageLabel.width/3, y: messageLabel.bottom+20, width: messageLabel.width/3, height: 35)
        
        
    }
}
